#include "setupwindow.h"
#include "ui_setupwindow.h"

#include <QDir>
#include <QSettings>
#include <QFontDialog>
#include <QColorDialog>

const QString defaultFormatDateTime = "$year/$month/$day$CRLF$hour:$minute:$second";
const QString defaultFormatNetIO = "$dev $max$CRLFr:$R w:$W";
const QString defaultFormatDiskIO = "$shortdev $max $temp$CRLFr:$R w:$W";
const QString defaultFormatDiskUsage = "$free/$total $shortmount";
const QString defaultFormatGPU = "GPU($ver) $free/$total $temp";
const QString defaultFormatCPU = "$dev $pcpu $freq $temp";
const QString defaultFormatProcList = "$pcpu $pid $cmd";

SetupWindow::SetupWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SetupWindow)
{
    ui->setupUi(this);
    loadSetting();
}

SetupWindow::~SetupWindow()
{
    delete ui;
}

QString SetupWindow::ColorToString(QColor color,bool bAlpha)
{
    QString str("");
    uint c = color.rgba();
    if(bAlpha)
        str = str.sprintf("#%08x",(c&0xffffffff));
    else
        str = str.sprintf("#%06x",(c&0x00ffffff));
    return str;
}

QString SetupWindow::ColorToStyleString(QColor color)
{
    return QString("color: rgba("+
                    QString::number(color.red())+", "+
                    QString::number(color.green())+", "+
                    QString::number(color.blue())+", "+
                    QString::number(color.alpha())+");");

}

QColor SetupWindow::StringToColor(QString str)
{
    bool ok;
    int r,g,b,a;

    a = str.mid(1,2).toInt(&ok,16);
    r = str.mid(3,2).toInt(&ok,16);
    g = str.mid(5,2).toInt(&ok,16);
    b = str.mid(7,2).toInt(&ok,16);

    return QColor(r,g,b,a);
}

QString SetupWindow::getFullSettingFileName(QString name)
{
    QString path = QDir::homePath();
    path.append(QDir::separator()).append(name);
    path = QDir::toNativeSeparators(path);
    return path;
}

void SetupWindow::loadSetting()
{
    QFont font;
    QColor color;
    QString path = getFullSettingFileName(".mymonrc");
    QSettings settings(path, QSettings::IniFormat);

    settings.setIniCodec("UTF-8");

    ui->spinBoxMainWidth->setValue(settings.value("geometry/width", 200).toInt());

    ui->doubleSpinBox_01->setValue(settings.value("Interval/CPUUsageCheckInterval", 1000).toInt() / 1000.0);
    ui->doubleSpinBox_02->setValue(settings.value("Interval/CoreTempCheckInterval", 10000).toInt() / 1000.0);
    ui->doubleSpinBox_03->setValue(settings.value("Interval/GPUTempCheckInterval", 10000).toInt() / 1000.0);
    ui->doubleSpinBox_04->setValue(settings.value("Interval/DiskUsageCheckInterval", 10000).toInt() / 1000.0);
    ui->doubleSpinBox_05->setValue(settings.value("Interval/DiskIOStateCheckInterval", 1000).toInt() / 1000.0);
    ui->doubleSpinBox_06->setValue(settings.value("Interval/DiskTempCheckInterval", 10000).toInt() / 1000.0);
    ui->doubleSpinBox_07->setValue(settings.value("Interval/NetIOStateCheckInterval", 1000).toInt() / 1000.0);
    ui->doubleSpinBox_08->setValue(settings.value("Interval/ProcessListCheckInterval", 1000).toInt() / 1000.0);

    ui->checkBoxModDateTime->setChecked(settings.value("Module/EnableDateTime",true).toBool());
    ui->checkBoxModCPUGraph->setChecked(settings.value("Module/EnableCPUGraph",true).toBool());
    ui->checkBoxModCPUTemp->setChecked(settings.value("Module/EnableCPUTemp",true).toBool());
    ui->checkBoxModCPUFreq->setChecked(settings.value("Module/EnableCPUFreq",true).toBool());
    ui->checkBoxModDiskUsage->setChecked(settings.value("Module/EnableDiskUsage",true).toBool());
    ui->checkBoxModDiskIO->setChecked(settings.value("Module/EnableDiskIO",true).toBool());
    ui->checkBoxModDiskTemp->setChecked(settings.value("Module/EnableDiskTemp",true).toBool());
    ui->checkBoxModNetIO->setChecked(settings.value("Module/EnableNetIO",true).toBool());
    ui->checkBoxModGPUState->setChecked(settings.value("Module/EnableGPUState",true).toBool());
    ui->checkBoxModProcessList->setChecked(settings.value("Module/EnableProcessList",false).toBool());

    ui->checkBoxStayOnTop->setChecked(settings.value("Main/StayOnTop",true).toBool());
    ui->checkBoxStayOnBottom->setChecked(settings.value("Main/StayOnBottom",false).toBool());
    ui->checkBoxMainDecorator->setChecked(settings.value("Main/Decorator",false).toBool());
    ui->checkBoxMainTransparent->setChecked(settings.value("Main/Transparent",true).toBool());
    ui->doubleSpinBoxOpacity->setValue(settings.value("Main/Opacity", 75).toInt() / 100.0);

    ui->checkBoxCPUBack->setChecked(settings.value("CPU/DrawBack",true).toBool());
    ui->checkBoxCPUBorder->setChecked(settings.value("CPU/DrawBorder",true).toBool());
    ui->checkBoxCPUHTML->setChecked(settings.value("CPU/HTMLFormat",true).toBool());
    ui->lineEditCPUGraphFormat->setText(settings.value("CPU/Format",defaultFormatCPU).toString());
    ui->spinBoxCPUGraphHeight->setValue(settings.value("CPU/Height",25).toInt());
    font.fromString(settings.value("CPU/Font",QFont("굴림체",10).toString()).toString());
    ui->pushButtonCPUGraphFont->setFont(font);
    ui->pushButtonCPUGraphFont->setText(font.family());
    color = StringToColor(settings.value("CPU/BackColor","#4f000000").toString());
    ui->pushButtonCPUBackColor->setText(ColorToString(color));
    ui->pushButtonCPUBackColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("CPU/BorderColor","#ff00007f").toString());
    ui->pushButtonCPUBorderColor->setText(ColorToString(color));
    ui->pushButtonCPUBorderColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("CPU/GraphColor","#ffff0000").toString());
    ui->pushButtonCPUGraphColor->setText(ColorToString(color));
    ui->pushButtonCPUGraphColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("CPU/TextColor","#ffffff00").toString());
    ui->pushButtonCPUTextColor->setText(ColorToString(color));
    ui->pushButtonCPUTextColor->setStyleSheet(ColorToStyleString(color));

    ui->checkBoxGPUBack->setChecked(settings.value("GPU/DrawBack",true).toBool());
    ui->checkBoxGPUBorder->setChecked(settings.value("GPU/DrawBorder",true).toBool());
    ui->checkBoxGPUHTML->setChecked(settings.value("GPU/HTMLFormat",true).toBool());
    ui->lineEditGPUFormat->setText(settings.value("GPU/Format",defaultFormatGPU).toString());
    ui->spinBoxGPUHeight->setValue(settings.value("GPU/Height",20).toInt());
    font.fromString(settings.value("GPU/Font",QFont("굴림체",10).toString()).toString());
    ui->pushButtonGPUFont->setFont(font);
    ui->pushButtonGPUFont->setText(font.family());
    color = StringToColor(settings.value("GPU/BackColor","#4f000000").toString());
    ui->pushButtonGPUBackColor->setText(ColorToString(color));
    ui->pushButtonGPUBackColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("GPU/BorderColor","#ff00007f").toString());
    ui->pushButtonGPUBorderColor->setText(ColorToString(color));
    ui->pushButtonGPUBorderColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("GPU/TextColor","#ffffff00").toString());
    ui->pushButtonGPUTextColor->setText(ColorToString(color));
    ui->pushButtonGPUTextColor->setStyleSheet(ColorToStyleString(color));

    ui->checkBoxDiskUsageBack->setChecked(settings.value("DiskUsage/DrawBack",true).toBool());
    ui->checkBoxDiskUsageBorder->setChecked(settings.value("DiskUsage/DrawBorder",true).toBool());
    ui->checkBoxDiskUsageHTML->setChecked(settings.value("DiskUsage/HTMLFormat",true).toBool());
    ui->lineEditDiskUsageFormat->setText(settings.value("DiskUsage/Format",defaultFormatDiskUsage).toString());
    ui->spinBoxDiskUsageHeight->setValue(settings.value("DiskUsage/Height",20).toInt());
    font.fromString(settings.value("DiskUsage/Font",QFont("굴림체",10).toString()).toString());
    ui->pushButtonDiskUsageFont->setFont(font);
    ui->pushButtonDiskUsageFont->setText(font.family());
    color = StringToColor(settings.value("DiskUsage/BackColor","#4f000000").toString());
    ui->pushButtonDiskUsageBackColor->setText(ColorToString(color));
    ui->pushButtonDiskUsageBackColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("DiskUsage/BorderColor","#ff00007f").toString());
    ui->pushButtonDiskUsageBorderColor->setText(ColorToString(color));
    ui->pushButtonDiskUsageBorderColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("DiskUsage/GraphColor","#ffff0000").toString());
    ui->pushButtonDiskUsageGraphColor->setText(ColorToString(color));
    ui->pushButtonDiskUsageGraphColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("DiskUsage/TextColor","#ffffff00").toString());
    ui->pushButtonDiskUsageTextColor->setText(ColorToString(color));
    ui->pushButtonDiskUsageTextColor->setStyleSheet(ColorToStyleString(color));

    ui->checkBoxDiskIOBack->setChecked(settings.value("DiskIO/DrawBack",true).toBool());
    ui->checkBoxDiskIOBorder->setChecked(settings.value("DiskIO/DrawBorder",true).toBool());
    ui->checkBoxDiskIOHTML->setChecked(settings.value("DiskIO/HTMLFormat",true).toBool());
    ui->lineEditDiskIOFormat->setText(settings.value("DiskIO/Format",defaultFormatDiskIO).toString());
    ui->spinBoxDiskIOHeight->setValue(settings.value("DiskIO/Height",20).toInt());
    font.fromString(settings.value("DiskIO/Font",QFont("굴림체",10).toString()).toString());
    ui->pushButtonDiskIOFont->setFont(font);
    ui->pushButtonDiskIOFont->setText(font.family());
    color = StringToColor(settings.value("DiskIO/BackColor","#4f000000").toString());
    ui->pushButtonDiskIOBackColor->setText(ColorToString(color));
    ui->pushButtonDiskIOBackColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("DiskIO/BorderColor","#ff00007f").toString());
    ui->pushButtonDiskIOBorderColor->setText(ColorToString(color));
    ui->pushButtonDiskIOBorderColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("DiskIO/GraphColor","#ffff0000").toString());
    ui->pushButtonDiskIOGraphColor->setText(ColorToString(color));
    ui->pushButtonDiskIOGraphColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("DiskIO/TextColor","#ffffff00").toString());
    ui->pushButtonDiskIOTextColor->setText(ColorToString(color));
    ui->pushButtonDiskIOTextColor->setStyleSheet(ColorToStyleString(color));

    ui->checkBoxNetIOBack->setChecked(settings.value("NetIO/DrawBack",true).toBool());
    ui->checkBoxNetIOBorder->setChecked(settings.value("NetIO/DrawBorder",true).toBool());
    ui->checkBoxNetIOHTML->setChecked(settings.value("NetIO/HTMLFormat",true).toBool());
    ui->lineEditNetIOFormat->setText(settings.value("NetIO/Format",defaultFormatNetIO).toString());
    ui->spinBoxNetIOHeight->setValue(settings.value("NetIO/Height",20).toInt());
    font.fromString(settings.value("NetIO/Font",QFont("굴림체",10).toString()).toString());
    ui->pushButtonNetIOFont->setFont(font);
    ui->pushButtonNetIOFont->setText(font.family());
    color = StringToColor(settings.value("NetIO/BackColor","#4f000000").toString());
    ui->pushButtonNetIOBackColor->setText(ColorToString(color));
    ui->pushButtonNetIOBackColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("NetIO/BorderColor","#ff00007f").toString());
    ui->pushButtonNetIOBorderColor->setText(ColorToString(color));
    ui->pushButtonNetIOBorderColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("NetIO/GraphColor","#ffff0000").toString());
    ui->pushButtonNetIOGraphColor->setText(ColorToString(color));
    ui->pushButtonNetIOGraphColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("NetIO/TextColor","#ffffff00").toString());
    ui->pushButtonNetIOTextColor->setText(ColorToString(color));
    ui->pushButtonNetIOTextColor->setStyleSheet(ColorToStyleString(color));

    ui->checkBoxDateTimeAnalog->setChecked(settings.value("DateTime/Analog",true).toBool());
    ui->checkBoxDateTimeBack->setChecked(settings.value("DateTime/DrawBack",true).toBool());
    ui->checkBoxDateTimeBorder->setChecked(settings.value("DateTime/DrawBorder",true).toBool());
    ui->checkBoxDateTimeHTML->setChecked(settings.value("DateTime/HTMLFormat",true).toBool());
    ui->lineEditDateTimeFormat->setText(settings.value("DateTime/Format",defaultFormatDateTime).toString());
    ui->spinBoxDateTimeHeight->setValue(settings.value("DateTime/Height",20).toInt());
    font.fromString(settings.value("DateTime/Font",QFont("굴림체",10).toString()).toString());
    ui->pushButtonDateTimeFont->setFont(font);
    ui->pushButtonDateTimeFont->setText(font.family());
    color = StringToColor(settings.value("DateTime/BackColor","#4f000000").toString());
    ui->pushButtonDateTimeBackColor->setText(ColorToString(color));
    ui->pushButtonDateTimeBackColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("DateTime/BorderColor","#ff00007f").toString());
    ui->pushButtonDateTimeBorderColor->setText(ColorToString(color));
    ui->pushButtonDateTimeBorderColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("DateTime/TextColor","#ffffff00").toString());
    ui->pushButtonDateTimeTextColor->setText(ColorToString(color));
    ui->pushButtonDateTimeTextColor->setStyleSheet(ColorToStyleString(color));

    ui->checkBoxProcListBack->setChecked(settings.value("ProcList/DrawBack",true).toBool());
    ui->checkBoxProcListBorder->setChecked(settings.value("ProcList/DrawBorder",true).toBool());
    ui->checkBoxProcListHTML->setChecked(settings.value("ProcList/HTMLFormat",true).toBool());
    ui->lineEditProcListFormat->setText(settings.value("ProcList/Format",defaultFormatProcList).toString());
    ui->spinBoxProcListHeight->setValue(settings.value("ProcList/Height",20).toInt());
    ui->spinBoxProcListCount->setValue(settings.value("ProcList/Count",5).toInt());
    font.fromString(settings.value("ProcList/Font",QFont("굴림체",10).toString()).toString());
    ui->pushButtonProcListFont->setFont(font);
    ui->pushButtonProcListFont->setText(font.family());
    color = StringToColor(settings.value("ProcList/BackColor","#4f000000").toString());
    ui->pushButtonProcListBackColor->setText(ColorToString(color));
    ui->pushButtonProcListBackColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("ProcList/BorderColor","#ff00007f").toString());
    ui->pushButtonProcListBorderColor->setText(ColorToString(color));
    ui->pushButtonProcListBorderColor->setStyleSheet(ColorToStyleString(color));
    color = StringToColor(settings.value("ProcList/TextColor","#ffffff00").toString());
    ui->pushButtonProcListTextColor->setText(ColorToString(color));
    ui->pushButtonProcListTextColor->setStyleSheet(ColorToStyleString(color));
}

void SetupWindow::saveSetting()
{
    QString path = getFullSettingFileName(".mymonrc");
    QSettings settings(path, QSettings::IniFormat);

    settings.setIniCodec("UTF-8");

    settings.setValue("geometry/width", ui->spinBoxMainWidth->value());

    settings.setValue("Interval/CPUUsageCheckInterval",(int)(ui->doubleSpinBox_01->value() * 1000.0));
    settings.setValue("Interval/CoreTempCheckInterval",(int)(ui->doubleSpinBox_02->value() * 1000.0));
    settings.setValue("Interval/GPUTempCheckInterval",(int)(ui->doubleSpinBox_03->value() * 1000.0));
    settings.setValue("Interval/DiskUsageCheckInterval",(int)(ui->doubleSpinBox_04->value() * 1000.0));
    settings.setValue("Interval/DiskIOStateCheckInterval",(int)(ui->doubleSpinBox_05->value() * 1000.0));
    settings.setValue("Interval/DiskTempCheckInterval",(int)(ui->doubleSpinBox_06->value() * 1000.0));
    settings.setValue("Interval/NetIOStateCheckInterval",(int)(ui->doubleSpinBox_07->value() * 1000.0));
    settings.setValue("Interval/ProcListCheckInterval",(int)(ui->doubleSpinBox_08->value() * 1000.0));

    settings.setValue("Module/EnableDateTime",ui->checkBoxModDateTime->isChecked());
    settings.setValue("Module/EnableCPUGraph",ui->checkBoxModCPUGraph->isChecked());
    settings.setValue("Module/EnableCPUTemp",ui->checkBoxModCPUTemp->isChecked());
    settings.setValue("Module/EnableCPUFreq",ui->checkBoxModCPUFreq->isChecked());
    settings.setValue("Module/EnableDiskUsage",ui->checkBoxModDiskUsage->isChecked());
    settings.setValue("Module/EnableDiskIO",ui->checkBoxModDiskIO->isChecked());
    settings.setValue("Module/EnableDiskTemp",ui->checkBoxModDiskTemp->isChecked());
    settings.setValue("Module/EnableNetIO",ui->checkBoxModNetIO->isChecked());
    settings.setValue("Module/EnableGPUState",ui->checkBoxModGPUState->isChecked());
    settings.setValue("Module/EnableProcList",ui->checkBoxModProcessList->isChecked());


    settings.setValue("Main/StayOnTop",ui->checkBoxStayOnTop->isChecked());
    settings.setValue("Main/StayOnBottom",ui->checkBoxStayOnBottom->isChecked());
    settings.setValue("Main/Decorator",ui->checkBoxMainDecorator->isChecked());
    settings.setValue("Main/Transparent",ui->checkBoxMainTransparent->isChecked());
    settings.setValue("Main/Opacity",(int)(ui->doubleSpinBoxOpacity->value() * 100));


    settings.setValue("CPU/DrawBack",ui->checkBoxCPUBack->isChecked());
    settings.setValue("CPU/DrawBorder",ui->checkBoxCPUBorder->isChecked());
    settings.setValue("CPU/HTMLFormat",ui->checkBoxCPUHTML->isChecked());
    settings.setValue("CPU/Format",ui->lineEditCPUGraphFormat->text());
    settings.setValue("CPU/Height",ui->spinBoxCPUGraphHeight->value());
    settings.setValue("CPU/Font",ui->pushButtonCPUGraphFont->font().toString());
    settings.setValue("CPU/BackColor",ui->pushButtonCPUBackColor->text());
    settings.setValue("CPU/BorderColor",ui->pushButtonCPUBorderColor->text());
    settings.setValue("CPU/GraphColor",ui->pushButtonCPUGraphColor->text());
    settings.setValue("CPU/TextColor",ui->pushButtonCPUTextColor->text());

    settings.setValue("GPU/DrawBack",ui->checkBoxGPUBack->isChecked());
    settings.setValue("GPU/DrawBorder",ui->checkBoxGPUBorder->isChecked());
    settings.setValue("GPU/HTMLFormat",ui->checkBoxGPUHTML->isChecked());
    settings.setValue("GPU/Format",ui->lineEditGPUFormat->text());
    settings.setValue("GPU/Height",ui->spinBoxGPUHeight->value());
    settings.setValue("GPU/Font",ui->pushButtonGPUFont->font().toString());
    settings.setValue("GPU/BackColor",ui->pushButtonGPUBackColor->text());
    settings.setValue("GPU/BorderColor",ui->pushButtonGPUBorderColor->text());
    settings.setValue("GPU/TextColor",ui->pushButtonGPUTextColor->text());

    settings.setValue("DiskUsage/DrawBack",ui->checkBoxDiskUsageBack->isChecked());
    settings.setValue("DiskUsage/DrawBorder",ui->checkBoxDiskUsageBorder->isChecked());
    settings.setValue("DiskUsage/HTMLFormat",ui->checkBoxDiskUsageHTML->isChecked());
    settings.setValue("DiskUsage/Format",ui->lineEditDiskUsageFormat->text());
    settings.setValue("DiskUsage/Height",ui->spinBoxDiskUsageHeight->value());
    settings.setValue("DiskUsage/Font",ui->pushButtonDiskUsageFont->font().toString());
    settings.setValue("DiskUsage/BackColor",ui->pushButtonDiskUsageBackColor->text());
    settings.setValue("DiskUsage/BorderColor",ui->pushButtonDiskUsageBorderColor->text());
    settings.setValue("DiskUsage/GraphColor",ui->pushButtonDiskUsageGraphColor->text());
    settings.setValue("DiskUsage/TextColor",ui->pushButtonDiskUsageTextColor->text());

    settings.setValue("DiskIO/DrawBack",ui->checkBoxDiskIOBack->isChecked());
    settings.setValue("DiskIO/DrawBorder",ui->checkBoxDiskIOBorder->isChecked());
    settings.setValue("DiskIO/HTMLFormat",ui->checkBoxDiskIOHTML->isChecked());
    settings.setValue("DiskIO/Format",ui->lineEditDiskIOFormat->text());
    settings.setValue("DiskIO/Height",ui->spinBoxDiskIOHeight->value());
    settings.setValue("DiskIO/Font",ui->pushButtonDiskIOFont->font().toString());
    settings.setValue("DiskIO/BackColor",ui->pushButtonDiskIOBackColor->text());
    settings.setValue("DiskIO/BorderColor",ui->pushButtonDiskIOBorderColor->text());
    settings.setValue("DiskIO/GraphColor",ui->pushButtonDiskIOGraphColor->text());
    settings.setValue("DiskIO/TextColor",ui->pushButtonDiskIOTextColor->text());

    settings.setValue("NetIO/DrawBack",ui->checkBoxNetIOBack->isChecked());
    settings.setValue("NetIO/DrawBorder",ui->checkBoxNetIOBorder->isChecked());
    settings.setValue("NetIO/HTMLFormat",ui->checkBoxNetIOHTML->isChecked());
    settings.setValue("NetIO/Format",ui->lineEditNetIOFormat->text());
    settings.setValue("NetIO/Height",ui->spinBoxNetIOHeight->value());
    settings.setValue("NetIO/Font",ui->pushButtonNetIOFont->font().toString());
    settings.setValue("NetIO/BackColor",ui->pushButtonNetIOBackColor->text());
    settings.setValue("NetIO/BorderColor",ui->pushButtonNetIOBorderColor->text());
    settings.setValue("NetIO/GraphColor",ui->pushButtonNetIOGraphColor->text());
    settings.setValue("NetIO/TextColor",ui->pushButtonNetIOTextColor->text());

    settings.setValue("DateTime/Analog",ui->checkBoxDateTimeAnalog->isChecked());
    settings.setValue("DateTime/DrawBack",ui->checkBoxDateTimeBack->isChecked());
    settings.setValue("DateTime/DrawBorder",ui->checkBoxDateTimeBorder->isChecked());
    settings.setValue("DateTime/HTMLFormat",ui->checkBoxDateTimeHTML->isChecked());
    settings.setValue("DateTime/Format",ui->lineEditDateTimeFormat->text());
    settings.setValue("DateTime/Height",ui->spinBoxDateTimeHeight->value());
    settings.setValue("DateTime/Font",ui->pushButtonDateTimeFont->font().toString());
    settings.setValue("DateTime/BackColor",ui->pushButtonDateTimeBackColor->text());
    settings.setValue("DateTime/BorderColor",ui->pushButtonDateTimeBorderColor->text());
    settings.setValue("DateTime/TextColor",ui->pushButtonDateTimeTextColor->text());

    settings.setValue("ProcList/DrawBack",ui->checkBoxProcListBack->isChecked());
    settings.setValue("ProcList/DrawBorder",ui->checkBoxProcListBorder->isChecked());
    settings.setValue("ProcList/HTMLFormat",ui->checkBoxProcListHTML->isChecked());
    settings.setValue("ProcList/Format",ui->lineEditProcListFormat->text());
    settings.setValue("ProcList/Count",ui->spinBoxProcListCount->value());
    settings.setValue("ProcList/Height",ui->spinBoxProcListHeight->value());
    settings.setValue("ProcList/Font",ui->pushButtonProcListFont->font().toString());
    settings.setValue("ProcList/BackColor",ui->pushButtonProcListBackColor->text());
    settings.setValue("ProcList/BorderColor",ui->pushButtonProcListBorderColor->text());
    settings.setValue("ProcList/TextColor",ui->pushButtonProcListTextColor->text());
}

void SetupWindow::on_pushButtonLoad_clicked()
{
    loadSetting();
}

void SetupWindow::on_pushButtonSave_clicked()
{
    saveSetting();
//    close();
}

void SetupWindow::setButtonFont(QPushButton *btn,QString msg)
{
    bool ok;
    QFont font = QFontDialog::getFont(
                    &ok,
                    btn->font(),
                    this,
                    msg );
    if( ok )
    {
        btn->setFont(font);
        btn->setText(font.family());
    }
}

void SetupWindow::setButtonColor(QPushButton *btn,QString msg)
{
    QColor color = QColorDialog::getColor(StringToColor(btn->text()),
                                          this, msg,
                                          QColorDialog::ShowAlphaChannel);
    if( color.isValid() )
    {
        btn->setText(ColorToString(color));
        btn->setStyleSheet(ColorToStyleString(color));
    }
}

void SetupWindow::on_pushButtonCPUGraphFont_clicked()
{
    setButtonFont(ui->pushButtonCPUGraphFont,"Select CPU Graph Font");
}

void SetupWindow::on_pushButtonGPUFont_clicked()
{
    setButtonFont(ui->pushButtonGPUFont,"Select GPU Font");
}

void SetupWindow::on_pushButtonDiskUsageFont_clicked()
{
    setButtonFont(ui->pushButtonDiskUsageFont,"Select Disk Usage Font");
}

void SetupWindow::on_pushButtonDiskIOFont_clicked()
{
    setButtonFont(ui->pushButtonDiskIOFont,"Select Disk IO Font");
}

void SetupWindow::on_pushButtonNetIOFont_clicked()
{
    setButtonFont(ui->pushButtonNetIOFont,"Select Net IO Font");
}

void SetupWindow::on_pushButtonDateTimeFont_clicked()
{
    setButtonFont(ui->pushButtonDateTimeFont,"Select Date and Time Font");
}

void SetupWindow::on_pushButtonProcListFont_clicked()
{
    setButtonFont(ui->pushButtonProcListFont,"Select Process List Font");
}

void SetupWindow::on_pushButtonCPUBorderColor_clicked()
{
    setButtonColor(ui->pushButtonCPUBorderColor,"Select Border Color");
}

void SetupWindow::on_pushButtonCPUBackColor_clicked()
{
    setButtonColor(ui->pushButtonCPUBackColor,"Select Background Color");
}

void SetupWindow::on_pushButtonCPUGraphColor_clicked()
{
    setButtonColor(ui->pushButtonCPUGraphColor,"Select Graph Color");
}

void SetupWindow::on_pushButtonCPUTextColor_clicked()
{
    setButtonColor(ui->pushButtonCPUTextColor,"Select Text Color");
}

void SetupWindow::on_pushButtonGPUBorderColor_clicked()
{
    setButtonColor(ui->pushButtonGPUBorderColor,"Select GPU Border Color");
}

void SetupWindow::on_pushButtonGPUBackColor_clicked()
{
    setButtonColor(ui->pushButtonGPUBackColor,"Select GPU Background Color");
}

void SetupWindow::on_pushButtonGPUTextColor_clicked()
{
    setButtonColor(ui->pushButtonGPUTextColor,"Select GPU Text Color");
}

void SetupWindow::on_pushButtonDiskUsageBorderColor_clicked()
{
    setButtonColor(ui->pushButtonDiskUsageBorderColor,"Select Disk Usage Border Color");
}

void SetupWindow::on_pushButtonDiskUsageBackColor_clicked()
{
    setButtonColor(ui->pushButtonDiskUsageBackColor,"Select Disk Usage Background Color");
}

void SetupWindow::on_pushButtonDiskUsageGraphColor_clicked()
{
    setButtonColor(ui->pushButtonDiskUsageGraphColor,"Select Disk Usage Graph Color");
}

void SetupWindow::on_pushButtonDiskUsageTextColor_clicked()
{
    setButtonColor(ui->pushButtonDiskUsageTextColor,"Select Disk Usage Text Color");
}

void SetupWindow::on_pushButtonDiskIOBorderColor_clicked()
{
    setButtonColor(ui->pushButtonDiskIOBorderColor,"Select Disk IO Border Color");
}

void SetupWindow::on_pushButtonDiskIOBackColor_clicked()
{
    setButtonColor(ui->pushButtonDiskIOBackColor,"Select Disk IO Background Color");
}

void SetupWindow::on_pushButtonDiskIOGraphColor_clicked()
{
    setButtonColor(ui->pushButtonDiskIOGraphColor,"Select Disk IO Graph Color");
}

void SetupWindow::on_pushButtonDiskIOTextColor_clicked()
{
    setButtonColor(ui->pushButtonDiskIOTextColor,"Select Disk IO Text Color");
}

void SetupWindow::on_pushButtonNetIOBorderColor_clicked()
{
    setButtonColor(ui->pushButtonNetIOBorderColor,"Select Net IO Border Color");
}

void SetupWindow::on_pushButtonNetIOBackColor_clicked()
{
    setButtonColor(ui->pushButtonNetIOBackColor,"Select Net IO Background Color");
}

void SetupWindow::on_pushButtonNetIOGraphColor_clicked()
{
    setButtonColor(ui->pushButtonNetIOGraphColor,"Select Net IO Graph Color");
}

void SetupWindow::on_pushButtonNetIOTextColor_clicked()
{
    setButtonColor(ui->pushButtonNetIOTextColor,"Select Net IO Text Color");
}

void SetupWindow::on_pushButtonDateTimeBorderColor_clicked()
{
    setButtonColor(ui->pushButtonDateTimeBorderColor,"Select Date Time Border Color");
}

void SetupWindow::on_pushButtonDateTimeBackColor_clicked()
{
    setButtonColor(ui->pushButtonDateTimeBackColor,"Select Date Time Background Color");
}

void SetupWindow::on_pushButtonDateTimeTextColor_clicked()
{
    setButtonColor(ui->pushButtonDateTimeTextColor,"Select Date Time Text Color");
}

void SetupWindow::on_pushButtonProcListBorderColor_clicked()
{
    setButtonColor(ui->pushButtonProcListBorderColor,"Select Process List Text Color");
}

void SetupWindow::on_pushButtonProcListBackColor_clicked()
{
    setButtonColor(ui->pushButtonProcListBackColor,"Select Process List Text Color");
}

void SetupWindow::on_pushButtonProcListTextColor_clicked()
{
    setButtonColor(ui->pushButtonProcListTextColor,"Select Process List Text Color");
}
